package com.yz.core.exception;

import com.yz.core.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @className: BlogExceptionHanlder
 * @author: shuishui
 * @date: 2023/01/03 20:31
 */
@ControllerAdvice
@Slf4j
public class BlogExceptionHanlder {
    //系统异常
    @ExceptionHandler(Exception.class)
    public R systemException(Exception e){
        log.error("系统宕机，拜拜",e);
        return R.error("系统宕机，拜拜");
    }
    //处理业务异常
    @ExceptionHandler(BaseException.class)
    @ResponseBody
    public R baseException(BaseException e) {
        log.error(e.getMsg(), e);
        return R.error(e.getMsg());
    }

}
